package com.reqresp; /**
 * @author wzm
 * @create 2023-09-19 14:28
 * project_name:javaweb2308
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/reqServlet01")
public class ReqServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //请求行
        //1.获取请求方式
        String method = request.getMethod();
        //2.获取项目的访问路径
        String contextPath = request.getContextPath();
        System.out.println("contextPath = " + contextPath);// /web06

        //3.获取项目的url  http://localhost:8088/web06/reqServlet01
        StringBuffer requestURL = request.getRequestURL();
        System.out.println("requestURL = " + requestURL);

        //4.获取uri /web06/reqServlet01
        String requestURI = request.getRequestURI();

        System.out.println("requestURI = " + requestURI);

        //5.获取get请求的参数（get） ?username=zss
        String queryString = request.getQueryString();
        System.out.println("queryString = " + queryString);

        //获取请求头 key-value
        String header = request.getHeader("user-agent");//浏览器的版本信息
        System.out.println("header = " + header);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        System.out.println("post请求");
        //获取Post请求的请求体数据
        //此方式只能获取纯文本信息  如果涉及到文件上传 需要单独使用另外的方法
        BufferedReader reader = request.getReader();//获取字符输入流
        String s = reader.readLine();//读取一行 username=zs&password=123456
        System.out.println("s = " + s);


        //字节输入流 文件数据使用
       // ServletInputStream inputStream = request.getInputStream();


    }
}
